<template>
  <drag-dialog
    custom-class="custom-dialog"
    class="border"
    :width="width"
    :title="title"
    append-to-body
    :close-on-click-modal="clickClose"
    :destroy-on-close="closeFree"
    v-model="_value"
  >
    <slot></slot>
    <template #footer>
      <div v-if="showFooter">
        <el-button
          size="default"
          @click="
            () => {
              _value = false
              $emit('cancel')
            }
          "
        >{{ cancelText }}</el-button
        >
        <el-button size="default" type="primary" @click="$emit('ok')">{{ okText }}</el-button>
      </div>
    </template>
  </drag-dialog>
</template>

<script>
export default {
  name: 'WDialog',
  components: {},
  props: {
    title: {
      type: String,
      default: ''
    },
    width: {
      type: String,
      default: '50%'
    },
    modelValue: {
      type: Boolean,
      default: false
    },
    clickClose: {
      type: Boolean,
      default: false
    },
    closeFree: {
      type: Boolean,
      default: false
    },
    showFooter: {
      type: Boolean,
      default: true
    },
    cancelText: {
      type: String,
      default: '取 消'
    },
    okText: {
      type: String,
      default: '确 定'
    },
    border: {
      type: Boolean,
      default: true
    }
  },
  emits: ['ok','update:modelValue'],
  install(Vue) {
    Vue.component('WDialog', this)
  },
  data() {
    return {}
  },
  computed: {
    _value: {
      get() {
        return this.modelValue
      },
      set(val) {
        this.$emit('update:modelValue', val)
      }
    }
  },
  methods: {}
}
</script>

<style lang="less" scoped>
:deep(.custom-dialog) {
  .drag-dialog__header {
    padding: 10px 20px;
    .drag-dialog__title {
      font-size: 17px;
    }
    .drag-dialog__headerbtn {
      top: 15px;
      .i {
        font-size: large;
      }
    }
  }

  .drag-dialog__footer {
    padding: 10px 20px;
  }
}

.border {
  :deep(.drag-dialog__header) {
    border-bottom: 1px solid #e8e8e8;
  }
  :deep(.drag-dialog__footer) {
    border-top: 1px solid #e8e8e8;
  }
}
</style>
